import 'dart:convert';

import 'package:trade/common/base/view_model.dart';
import 'package:trade/common/service/td_service.dart';
import 'package:trade/data/bean/user_info_bean.dart';

const String USER_CACHE_KEY = "USER_CACHE_KEY";

class UserModel extends ViewModel {
  UserInfoBean _info = UserInfoBean();

  UserInfoBean get info => _info;

  set info(UserInfoBean newValue) {
    _info = newValue;
    service.cache.setMap(USER_CACHE_KEY, this._info.toJson());
    notifyListeners();
  }

  UserModel() {
    var userCache = service.cache.get(USER_CACHE_KEY);
    if (userCache != null) {
      _info = UserInfoBean.fromJson(jsonDecode(userCache));
    }
  }
}
